package com.BXuan.LeetCode.数组.数组_差分;

/**
 * 1109.航班预定统计
 */
public class Solution {
    public int[] corpFlightBookings(int[][] bookings, int n) {
        // 这里定义差分数组，并且设置长度
        int[] nums = new int[n];
        // 调用Difference工具类，在题目里面需要自己实现 》 构造器方法、增加方法、返回结果方法
        Difference difference = new Difference(nums);

        for (int[] booking : bookings){
            int start = booking[0] - 1;
            int end = booking[1] - 1;
            int seat = booking[2];
            difference.increment(start, end, seat);
        }

        return difference.result();
    }
}

/**
 * 1094.拼车
 */
class Solution02 {
    // 定义一个差分数组
    private int[] diff = new int[1001];
    // 初始化差分数组
    Difference difference = new Difference(diff);

    public boolean carPooling(int[][] trips, int capacity) {
        for (int[] trip : trips){
            int personNum =  trip[0];
            int start = trip[1];
            int end = trip[2] - 1;
            difference.increment(start, end, personNum);
        }
        int[] result = difference.result();

        for (int res : result){
            if (res > capacity){
                return false;
            }
        }
        return true;
    }
}